package com.zkingsoft.service.impl;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.matrix.core.constance.MatrixConstance;
import com.matrix.core.constance.SystemErrorCode;
import com.matrix.core.exception.GlobleException;
import com.matrix.core.pojo.PaginationVO;
import com.matrix.core.tools.ModelUtils;
import com.matrix.core.tools.UUIDUtil;
import com.matrix.core.tools.WebUtil;
import com.zkingsoft.bean.BizCollageInfo;
import com.zkingsoft.common.bean.SysUsers;
import com.zkingsoft.dao.BizCollageInfoDao;
import com.zkingsoft.service.BizCollageInfoService;

/**
 * @description service接口实现类(团信息)
 * @author 何明
 * @date 2018-05-23 00:08
 */
@Service
public class  BizCollageInfoServiceImpl implements  BizCollageInfoService{

	
	@Autowired
	private BizCollageInfoDao bizCollageInfoDao;
	
	
	@Override
	public int add(BizCollageInfo bizCollageInfo){
		// 设置基本字段信息
		/*SysUsers loginUser = WebUtil.getSessionAttribute(MatrixConstance.LOGIN_KEY);
		bizCollageInfo.setCreateBy(loginUser.getSuName());
		bizCollageInfo.setUpdateBy(loginUser.getSuName());
		bizCollageInfo.setCinfoId(UUIDUtil.getRandomID());*/
		return bizCollageInfoDao.insert(bizCollageInfo);
		
	}
	
	@Override
	public int batchAdd(List<BizCollageInfo>  bizCollageInfoList) {
		//这里没有做基本字段的设置，如有需要请自己实现	
		int num = 0;
		int c = 10000;
		int size = bizCollageInfoList.size()/c + 1;
		for(int i=0; i<size; i++) {
			int begin = i*c;
			int end = (i+1)*c;
			end = end >= bizCollageInfoList.size() ? bizCollageInfoList.size() : end;
			List<BizCollageInfo> insertList = bizCollageInfoList.subList(begin, end);
			num += bizCollageInfoDao.batchInsert(insertList);
		}
		return num;
		
	}
	
	
   	
    @Override
	public int modifyByMap(BizCollageInfo oldBizCollageInfo
	,BizCollageInfo newBizCollageInfo){
	
		Map<String, Object> modifyMap = null;
		try {
			if (!ModelUtils.isModified(oldBizCollageInfo, newBizCollageInfo)) {
				return MatrixConstance.DML_SUCCESSS;
			}
			modifyMap = ModelUtils.comparePojo2Map(oldBizCollageInfo, newBizCollageInfo);
		} catch (Exception e) {
			throw new GlobleException(SystemErrorCode.DATA_UPDATE_FAIL, e, newBizCollageInfo);
		}
		if (modifyMap.size() > 0) {
			modifyMap.put("cinfoId", oldBizCollageInfo.getCinfoId());
			bizCollageInfoDao.updateByMap(modifyMap);
		}
		return MatrixConstance.DML_SUCCESSS;
	}
	
	@Override
	public int modifyByModel(BizCollageInfo bizCollageInfo){
	
		return bizCollageInfoDao.updateByModel(bizCollageInfo);
	
	}
	
	
	
	@Override
	public int remove(List<String> list){
	
		return bizCollageInfoDao.deleteByIds(list);
	
	}

	@Override
	public int removeById(String cinfoId){
	
		return bizCollageInfoDao.deleteById(cinfoId);
	
	}
	
	@Override
	public int removeByModel(BizCollageInfo bizCollageInfo){
	
		return bizCollageInfoDao.deleteByModel(bizCollageInfo);
	
	}
	
	
	@Override
	public List<BizCollageInfo> findInPage(BizCollageInfo bizCollageInfo,  PaginationVO pageVo){
	
		return bizCollageInfoDao.selectInPage(bizCollageInfo , pageVo);
	
	}
	
	@Override
	public List<BizCollageInfo> findByModel(BizCollageInfo bizCollageInfo){
	
		return bizCollageInfoDao.selectByModel(bizCollageInfo);
	
	}
	
	@Override
	public int  findTotal(BizCollageInfo bizCollageInfo){
	
		return bizCollageInfoDao.selectTotalRecord(bizCollageInfo);
	
	}
	
	@Override
	public BizCollageInfo  findById(String cinfoId){
	
		return bizCollageInfoDao.selectById(cinfoId);
	
	}

   	
	
	
}